Skip to main content

08 - MQTT Internet of Things

Overview


MQTT is a publish-subscribe messaging protocol that is designed for use in IoT applications and is relatively straightforward to implement.

Getting Started

The following tutorial uses KittenBot's IoT platform as the server. Before using it, please register at https://iot.kittenbot.cn/.

  1. Create an MQTT Topic

    image.png

  2. Set the topic path (filling in the topic username and password can set the topic as private. You can leave it blank; the topic will be a public topic. Anyone with the topic path can view it.)

    image.png warning The topic is unique across the platform. Please set a relatively personalized topic. Try not to set it as a common name like temp.

  3. After creation, click Connect to Topic

    image.png

  4. Send a test message <br />image.png

    danger

    You may need to refresh to see the new message.<br />image.png

How to Use


Brick Introduction

Programming BrickFunction Introduction
image-20240321152705899Connect to WiFi
image-20240321152714668Return WiFi IP address, return 0.0.0.0 if not connected
image-20240321152722507Connect to Meow home MQTT server, public topic
image-20240321152732786If you need to use a private MQTT topic, you can use this brick to enter the username and password
image-20240321152747254Subscribe to a topic
image-20240321152753385Send a message to a topic
image-20240321152802424Read the topic message, you need to subscribe first

Case 1 - Smart home lamp

danger

This case introduces the communication control of two Grapeboards. If you only have one Grapeboard, you can use it as the controlled receiving end, and you can directly send instructions to the corresponding topic through the MQTT server page for control.

  • Effect: You can remotely control the device using the MQTT server as a medium. <br/><br/> image.png

  • Program - Control End

    image-20240321152954206

  • Program - Controlled End

    image-20240321153200323